package airportCoordination;

import java.util.Calendar;


public class PacketLog implements Comparable<PacketLog>{
	private int port;
	private int id;
	private String ip;
	private String message;
	private Calendar timestamp;
	private boolean error;
	private boolean ping;
	
	public PacketLog(int id_m, String i, int p, String m)
	{
		timestamp = Calendar.getInstance();
		port = p;
		ip = i;
		message = m;
		id= id_m;
		error = false;
		ping = false;
	}

	public PacketLog(int id_m, String i, int p, String m, boolean pi)
	{
		timestamp = Calendar.getInstance();
		port = p;
		ip = i;
		message = m;
		id= id_m;
		error = false;
		ping = pi;
	}
	
	public PacketLog(PacketLog p)
	{
		timestamp = Calendar.getInstance();
		port = p.port;
		ip = p.ip;
		message = p.message;
		id = p.id;
		error = false;		
	}
	
	public int get_port()
	{
		return port;
	}
	
	public String get_ip()
	{
		return ip;
	}
	
	public boolean is_ping()
	{
		return ping;
	}
	
	public String get_msg()
	{
		return message;
	}
	
	public boolean timedout(int s_timeout)
	{
		Calendar now = Calendar.getInstance();
		now.add(Calendar.SECOND, -s_timeout);
		return timestamp.before(now);
	}
	
	public boolean is_id(int id_m)
	{
		return id_m == id;
	}

	public int compareTo(PacketLog pack) {
		if (id > pack.id)
			return 1;
		if (id < pack.id)
			return -1;
		return ip.compareTo(pack.ip);
	}
	
	public void set_error(boolean e)
	{
		error = e;
	}
	
	public boolean error()
	{
		return error;
	}
}
